package com.yanyan.sannuomin.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yanyan.sannuomin.domain.SccMedicalReport;
import com.yanyan.sannuomin.result.Result;
import com.yanyan.sannuomin.result.ResultCode;
import com.yanyan.sannuomin.service.MaintainService;

import com.yanyan.sannuomin.vo.MaintainVo;
import com.yanyan.sannuomin.vo.MaintainVo1;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/maintain")
@Api(tags = "系统设置接口")
public class MaintainController {

    @Resource
    private MaintainService maintainService;



    /**
     * 查询用户
     * @param
     * @param
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "findAll1", method = RequestMethod.GET)
    @ApiOperation(value = "查询用户", notes = "根据条件分页查询", httpMethod = "GET")
    public Result findMaintain(Integer page, Integer limit, String searchParams) throws  Exception{
        System.out.println("搜索条件："+searchParams);
        ObjectMapper objectMapper = new ObjectMapper();
        MaintainVo1 maintainVo1 = null;
        if(searchParams != null){
            maintainVo1= objectMapper.readValue(searchParams, MaintainVo1.class);
        }
        System.out.println("搜索结果："+maintainVo1);
        Page page1 = PageHelper.startPage(page, limit);
        List<SccMedicalReport> sccMedicalReports = maintainService.findMaintain(maintainVo1);

        for (SccMedicalReport sccMedicalReport : sccMedicalReports) {
         sccMedicalReport.setQujian(sccMedicalReport.getReferenceLow()+"~"+sccMedicalReport.getReferenceHigh());
        }

        PageInfo pageInfo=new PageInfo(sccMedicalReports);


        return Result.ok(ResultCode.SUCCESS,pageInfo.getTotal(),sccMedicalReports);

    }


}
